package com.netease.nie.service;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.netease.nie.base.exceptions.BusinessException;
import com.netease.nie.base.utils.CopyUtils;
import com.netease.nie.constants.BusinessConstants;
import com.netease.nie.dao.CategoryDao;
import com.netease.nie.dto.CategoryDto;
import com.netease.nie.model.Category;

/**
 * 
 * @author wwbn3695
 * @CreateDate June 21st, 2016
 */
@Service
public class CategoryServiceImpl implements CategoryService {

	@Autowired
	private CategoryDao categoryDao;
	
	public List<CategoryDto> listAllCategoryDtos() {
		List<Category> categoryList = categoryDao.listAllCategory();
		if (CollectionUtils.isEmpty(categoryList))
			throw new BusinessException(BusinessConstants.NO_VALID_GOODS_CATEGORY.getCode(), "商品类目无效");
		List<CategoryDto> categoryDtoList = CopyUtils.copyOriginListToDestList(categoryList, CategoryDto.class);
		return categoryDtoList;
	}
	
}
